#ifndef CACHE_MANAGER_H
#define CACHE_MANAGER_H

#include "storage_system.h"
#include <stdint.h>

// 缓存条目结构
typedef struct {
    page_id_t page_id;
    uint8_t data[PAGE_SIZE];
    int is_dirty;
    uint32_t last_access;
    uint32_t access_count;
} cache_entry_t;

// 缓存管理器接口
typedef struct cache_manager cache_manager_t;

// 创建和销毁缓存管理器
cache_manager_t* cache_manager_create(uint32_t capacity, cache_replacement_policy_t policy);
void cache_manager_destroy(cache_manager_t* manager);

// 设置数据目录
void cache_manager_set_data_directory(cache_manager_t* manager, const char* data_dir);

// 缓存操作
storage_error_t cache_manager_get(cache_manager_t* manager, page_id_t page_id, uint8_t* buffer);
storage_error_t cache_manager_put(cache_manager_t* manager, page_id_t page_id, const uint8_t* data);
storage_error_t cache_manager_remove(cache_manager_t* manager, page_id_t page_id);
storage_error_t cache_manager_flush(cache_manager_t* manager, page_id_t page_id);
storage_error_t cache_manager_flush_all(cache_manager_t* manager);

// 缓存统计
uint32_t cache_manager_get_hits(cache_manager_t* manager);
uint32_t cache_manager_get_misses(cache_manager_t* manager);
uint32_t cache_manager_get_size(cache_manager_t* manager);
uint32_t cache_manager_get_capacity(cache_manager_t* manager);

// 查找页面在缓存中的位置
int cache_manager_find(cache_manager_t* manager, page_id_t page_id);

#endif // CACHE_MANAGER_H